package cn.itcast.search.listen;

import cn.itcast.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ItemQueueListen {
    @Autowired
    private SearchService searchService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("item_up_queue"),
            exchange = @Exchange(value = "hmall.topic",type = ExchangeTypes.TOPIC),
            key = "hmall.insert"
    ))
    public void listenInsertQueue(Long id){
        searchService.insertById(id);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("item_down_queue"),
            exchange = @Exchange(value = "hmall.topic",type = ExchangeTypes.TOPIC),
            key = "hmall.delete"
    ))
    public void listenDeleteQueue(Long id){
        searchService.deleteById(id);
    }
}
